<?php

namespace Dongasai\WkProtoPhp\Enums;

/**
 * 设备类型枚举
 * 使用PHP 8枚举语法
 */
enum DeviceFlag: int
{
    case ANDROID = 0;      // Android应用
    case IOS = 1;          // iOS应用
    case WEB = 2;          // 网页应用
    case PC = 3;           // 桌面应用
    case MOBILE_WEB = 4;   // 移动网页
    case TABLET = 5;       // 平板设备
    case SMART_TV = 6;     // 智能电视
    case WATCH = 7;        // 智能手表
    case CAR = 8;          // 车载设备
    case IOT = 9;          // 物联网设备
    case MAC = 10;         // macOS应用
    case LINUX = 11;       // Linux应用
    case WINDOWS = 12;     // Windows应用
    case HARMONY = 13;     // 鸿蒙应用
    case GAME_CONSOLE = 14; // 游戏主机
    case VR = 15;          // VR设备
    case AR = 16;          // AR设备
    case DRONE = 17;       // 无人机
    case ROBOT = 18;       // 机器人
    case SMART_SPEAKER = 19; // 智能音箱
    case CUSTOM_DEVICE_1 = 90;  // 自定义设备1
    case CUSTOM_DEVICE_2 = 91;  // 自定义设备2
    case CUSTOM_DEVICE_3 = 92;  // 自定义设备3
    case CUSTOM_DEVICE_4 = 93;  // 自定义设备4
    case CUSTOM_DEVICE_5 = 94;  // 自定义设备5
    case CUSTOM_DEVICE_6 = 95;  // 自定义设备6
    case CUSTOM_DEVICE_7 = 96;  // 自定义设备7
    case CUSTOM_DEVICE_8 = 97;  // 自定义设备8
    case CUSTOM_DEVICE_9 = 98;  // 自定义设备9
    case SYSTEM = 99;      // 系统服务

    /**
     * 获取设备类型的字符串表示
     */
    public function toString(): string
    {
        return $this->name;
    }

    /**
     * 转换为uint8
     */
    public function toUint8(): int
    {
        return $this->value & 0xFF;
    }

    /**
     * 从值创建枚举实例
     */
    public static function fromValue(int $value): self
    {
        return self::from($value);
    }

    /**
     * 检查是否为移动设备
     */
    public function isMobile(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::MOBILE_WEB, self::TABLET, self::WATCH]);
    }

    /**
     * 检查是否为Android设备
     */
    public function isAndroid(): bool
    {
        return in_array($this, [self::ANDROID, self::TABLET, self::WATCH, self::CAR, self::SMART_TV, self::GAME_CONSOLE]);
    }

    /**
     * 检查是否为iOS设备
     */
    public function isIOS(): bool
    {
        return in_array($this, [self::IOS, self::TABLET, self::WATCH, self::CAR, self::SMART_TV]);
    }

    /**
     * 检查是否为桌面设备
     */
    public function isDesktop(): bool
    {
        return in_array($this, [self::PC, self::MAC, self::WINDOWS, self::LINUX, self::WEB]);
    }

    /**
     * 检查是否为可穿戴设备
     */
    public function isWearable(): bool
    {
        return in_array($this, [self::WATCH, self::VR, self::AR]);
    }

    /**
     * 检查是否为智能设备
     */
    public function isSmartDevice(): bool
    {
        return in_array($this, [self::SMART_TV, self::CAR, self::IOT, self::SMART_SPEAKER, self::DRONE, self::ROBOT]);
    }

    /**
     * 检查是否为游戏设备
     */
    public function isGaming(): bool
    {
        return in_array($this, [self::GAME_CONSOLE, self::VR, self::AR]);
    }

    /**
     * 检查是否为系统设备
     */
    public function isSystem(): bool
    {
        return $this === self::SYSTEM;
    }

    /**
     * 检查是否为移动端设备
     */
    public function isMobilePlatform(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::MOBILE_WEB, self::TABLET]);
    }

    /**
     * 检查是否为嵌入式设备
     */
    public function isEmbedded(): bool
    {
        return in_array($this, [self::IOT, self::CAR, self::DRONE, self::ROBOT, self::SMART_SPEAKER]);
    }

    /**
     * 获取设备类型描述
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::ANDROID => 'Android应用',
            self::IOS => 'iOS应用',
            self::WEB => '网页应用',
            self::PC => '桌面应用',
            self::MOBILE_WEB => '移动网页',
            self::TABLET => '平板设备',
            self::SMART_TV => '智能电视',
            self::WATCH => '智能手表',
            self::CAR => '车载设备',
            self::IOT => '物联网设备',
            self::SYSTEM => '系统服务',
            self::MAC => 'macOS应用',
            self::LINUX => 'Linux应用',
            self::WINDOWS => 'Windows应用',
            self::HARMONY => '鸿蒙应用',
            self::GAME_CONSOLE => '游戏主机',
            self::VR => 'VR设备',
            self::AR => 'AR设备',
            self::DRONE => '无人机',
            self::ROBOT => '机器人',
            self::SMART_SPEAKER => '智能音箱',
            self::CUSTOM_DEVICE_1 => '自定义设备1',
            self::CUSTOM_DEVICE_2 => '自定义设备2',
            self::CUSTOM_DEVICE_3 => '自定义设备3',
            self::CUSTOM_DEVICE_4 => '自定义设备4',
            self::CUSTOM_DEVICE_5 => '自定义设备5',
            self::CUSTOM_DEVICE_6 => '自定义设备6',
            self::CUSTOM_DEVICE_7 => '自定义设备7',
            self::CUSTOM_DEVICE_8 => '自定义设备8',
            self::CUSTOM_DEVICE_9 => '自定义设备9',
            self::SYSTEM => '系统服务',
        };
    }

    /**
     * 获取设备类型分类
     */
    public function getCategory(): string
    {
        return match ($this) {
            self::ANDROID, self::IOS, self::HARMONY, self::MOBILE_WEB => '移动端',
            self::WEB, self::PC, self::MAC, self::WINDOWS, self::LINUX => '桌面端',
            self::TABLET => '平板端',
            self::WATCH, self::VR, self::AR => '可穿戴',
            self::SMART_TV, self::CAR, self::IOT, self::SMART_SPEAKER, self::DRONE, self::ROBOT => '智能设备',
            self::GAME_CONSOLE => '游戏设备',
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => '自定义设备',
            self::SYSTEM => '系统服务',
        };
    }

    /**
     * 获取设备操作系统
     */
    public function getOS(): string
    {
        return match ($this) {
            self::ANDROID => 'Android',
            self::IOS => 'iOS',
            self::TABLET => 'Tablet OS',
            self::WATCH => 'Watch OS',
            self::CAR => '车载系统',
            self::SMART_TV => 'TV OS',
            self::PC, self::WINDOWS => 'Windows',
            self::MAC => 'macOS',
            self::LINUX => 'Linux',
            self::HARMONY => 'HarmonyOS',
            self::WEB, self::MOBILE_WEB => 'Web',
            self::GAME_CONSOLE => '游戏主机系统',
            self::VR, self::AR => 'VR/AR系统',
            self::IOT, self::SMART_SPEAKER => 'IoT系统',
            self::DRONE, self::ROBOT => '嵌入式系统',
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => '自定义系统',
            self::SYSTEM => '系统服务',
        };
    }

    /**
     * 获取设备优先级（用于多设备同步）
     */
    public function getPriority(): int
    {
        return match ($this) {
            self::ANDROID => 12,        // Android优先级最高
            self::IOS => 11,           // iOS次之
            self::PC => 10,            // 桌面应用
            self::MAC => 9,            // macOS应用
            self::TABLET => 8,         // 平板设备
            self::WEB => 7,            // 网页应用
            self::MOBILE_WEB => 6,      // 移动网页
            self::WATCH => 5,          // 智能手表
            self::CAR => 4,            // 车载设备
            self::SMART_TV => 3,       // 智能电视
            self::IOT => 2,            // 物联网设备
            self::SMART_SPEAKER => 2,  // 智能音箱
            self::WINDOWS => 9,        // Windows应用
            self::LINUX => 8,         // Linux应用
            self::HARMONY => 11,       // 鸿蒙应用
            self::GAME_CONSOLE => 7,   // 游戏主机
            self::VR => 6,             // VR设备
            self::AR => 6,             // AR设备
            self::DRONE => 3,          // 无人机
            self::ROBOT => 3,          // 机器人
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => 2,  // 自定义设备优先级
            self::SYSTEM => 1,         // 系统服务优先级最低
        };
    }

    /**
     * 检查是否支持推送通知
     */
    public function supportsPush(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::PC, self::MAC]);
    }

    /**
     * 检查是否支持语音功能
     */
    public function supportsVoice(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::CAR, self::SMART_TV, self::SMART_SPEAKER]);
    }

    /**
     * 检查是否支持视频功能
     */
    public function supportsVideo(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::PC, self::MAC, self::TABLET, self::SMART_TV, self::CAR, self::VR, self::AR]);
    }

    /**
     * 检查是否支持定位功能
     */
    public function supportsLocation(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::CAR, self::DRONE, self::VR, self::AR]);
    }

    /**
     * 检查是否支持生物识别
     */
    public function supportsBiometrics(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::PC, self::MAC]);
    }

    /**
     * 检查是否支持NFC
     */
    public function supportsNFC(): bool
    {
        return in_array($this, [self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::CAR]);
    }

    /**
     * 获取设备屏幕类型
     */
    public function getScreenType(): string
    {
        return match ($this) {
            self::ANDROID, self::IOS, self::MOBILE_WEB => '小屏幕',
            self::TABLET => '中屏幕',
            self::PC, self::MAC, self::WINDOWS, self::LINUX, self::WEB => '大屏幕',
            self::SMART_TV => '超大屏幕',
            self::WATCH => '微型屏幕',
            self::CAR => '车载屏幕',
            self::GAME_CONSOLE => '游戏屏幕',
            self::VR => 'VR头显',
            self::AR => 'AR眼镜',
            self::IOT, self::SMART_SPEAKER, self::DRONE, self::ROBOT => '无屏幕',
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => '未知屏幕',
            self::SYSTEM => '无屏幕',
        };
    }

    /**
     * 获取设备连接类型
     */
    public function getConnectionType(): string
    {
        return match ($this) {
            self::ANDROID, self::IOS, self::TABLET, self::WATCH, self::PC, self::MAC, self::WINDOWS, self::LINUX => '网络连接',
            self::WEB, self::MOBILE_WEB => '浏览器连接',
            self::CAR, self::SMART_TV, self::GAME_CONSOLE => 'WiFi连接',
            self::IOT, self::SMART_SPEAKER, self::DRONE, self::ROBOT => '物联网连接',
            self::VR, self::AR => '专用连接',
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => '自定义连接',
            self::SYSTEM => '系统连接',
        };
    }

    /**
     * 获取设备使用场景
     */
    public function getUseCase(): string
    {
        return match ($this) {
            self::ANDROID, self::IOS => '移动通信',
            self::PC, self::MAC, self::WINDOWS, self::LINUX => '办公娱乐',
            self::WEB, self::MOBILE_WEB => '网页浏览',
            self::TABLET => '移动办公',
            self::WATCH => '健康监测',
            self::CAR => '车载信息',
            self::SMART_TV => '家庭娱乐',
            self::GAME_CONSOLE => '游戏娱乐',
            self::VR, self::AR => '沉浸体验',
            self::IOT => '智能家居',
            self::SMART_SPEAKER => '语音助手',
            self::DRONE => '航拍作业',
            self::ROBOT => '自动化服务',
            self::CUSTOM_DEVICE_1, self::CUSTOM_DEVICE_2, self::CUSTOM_DEVICE_3, self::CUSTOM_DEVICE_4, self::CUSTOM_DEVICE_5,
            self::CUSTOM_DEVICE_6, self::CUSTOM_DEVICE_7, self::CUSTOM_DEVICE_8, self::CUSTOM_DEVICE_9 => '自定义应用',
            self::SYSTEM => '系统管理',
        };
    }
}

/**
 * 设备等级枚举
 * 使用PHP 8枚举语法
 */
enum DeviceLevel: int
{
    case SLAVE = 0; // 从设备
    case MASTER = 1; // 主设备

    /**
     * 获取设备等级的字符串表示
     */
    public function toString(): string
    {
        return $this->name;
    }

    /**
     * 从值创建枚举实例
     */
    public static function fromValue(int $value): self
    {
        return self::from($value);
    }

    /**
     * 检查是否为主设备
     */
    public function isMaster(): bool
    {
        return $this === self::MASTER;
    }

    /**
     * 检查是否为从设备
     */
    public function isSlave(): bool
    {
        return $this === self::SLAVE;
    }

    /**
     * 获取设备等级描述
     */
    public function getDescription(): string
    {
        return match ($this) {
            self::MASTER => '主设备',
            self::SLAVE => '从设备',
        };
    }
}